/*
 * @lc app=leetcode.cn id=670 lang=csharp
 *
 * [670] 最大交换
 */

// @lc code=start
public class Solution {
    public int MaximumSwap(int num) {
        var nums = num.ToString().ToCharArray();
        var max = num;
        for (int i = 0; i < nums.Length; i++)
        {
            for (int j = i + 1; j < nums.Length; j++)
            {
                Swap(nums, i, j);
                max = Math.Max(max, int.Parse(new string(nums)));
                Swap(nums, i, j);
            }
        }
        return max;
    }
    
    private void Swap(char[] nums, int i, int j)
    {
        var temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
}
// @lc code=end

